package com.cat.graphTheory;

import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/keys-and-rooms/description/
 * @create 2025/9/18 20:13
 * @since JDK17
 */

public class Solution03 {
    List<List<Integer>> rooms;
    boolean[]vis;
    void dfs(int cur) {
        List<Integer> list = rooms.get(cur);
        vis[cur] = true;
        for (Integer x : list) {
            if (!vis[x]) {
                dfs(x);
            }
        }
    }
    public boolean canVisitAllRooms(List<List<Integer>> rooms) {
        int n = rooms.size();
        vis = new boolean[n];
        this.rooms = rooms;
        dfs(0);
        for (int i = 0; i < n; i++) {
            if (!vis[i]) {
                return false;
            }
        }
        return true;
    }
}
